<template>
  <div>

    <el-row>
      <mu-appbar title="每日新增代理历史" style="background-color:#409EFF">
        <mu-icon-button  icon="arrow_back_ios" slot="left" :to="{name: 'Home' }"/>
      </mu-appbar>
    </el-row>

    <el-row>
      <el-table
        :data="tableData"
        style="width: 100%">
        <el-table-column
          prop="newAgentNum"
          label="新增代理">
        </el-table-column>
        <el-table-column
          prop="createTime"
          label="日期">
        </el-table-column>
      </el-table>
    </el-row>

    <el-row>
      <center>
        <el-pagination
          small
          layout="prev, pager, next"
          :total="condition.total"
          :page-size="condition.pageSize"
          :current-page="condition.currentPage"
          @current-change="handleCurrentChange">
        </el-pagination>
      </center>
    </el-row>

  </div>
</template>

<style scoped>
  .el-row {
    margin-bottom: 16px;
  }
  .el-col {
    margin-bottom: 8px;
  }
</style>

<script>
import Qs from 'qs'
  export default {
    data () {
      return {
        tableData: [],
        condition: {
          currentPage: 1,
          pageSize: 10,
          total: 0
        }
      }
    },
    methods: {
      init () {
        this.getNewAgentNumberHistory()
      },
      getNewAgentNumberHistory () {
        let data = Qs.stringify(this.condition)
        this.$axios({
          method: 'post',
          url: '/api/GmService.getNewAgentNumHistory',
          data
        })
        .then(resp => {
          if (resp.data.status === 'success') {
            this.tableData = resp.data.data
            this.condition.total = resp.data.total
          } else {
            this.$message({
              showClose: true,
              message: resp.data.cause,
              type: 'warning'
            })
          }
        })
        .catch(e => {
          console.log(e)
          this.$message({
            showClose: true,
            message: '服务器出小差了',
            type: 'error'
          })
        })
      },
      handleCurrentChange (val) {
        this.condition.currentPage = val
        this.getNewAgentNumberHistory()
      },
    },
    mounted () {
      this.init()
    }
  }
</script>
